// 角色管理管理模块接口
import request from '@/utils/request'

enum API {
  // 查询列表接口
  ROLE_LIST_URL = '/admin/acl/role/',
  // 删除接口
  ROLE_DELETE_URL = '/admin/acl/role/remove/',
  // 新增接口
  ROLE_ADD_URL = '/admin/acl/role/save',
  // 更新接口
  ROLE_UPDATE_URL = '/admin/acl/role/update',
  // 获取角色列表接口
  ROLE_PERMISSION_LIST_URL = '/admin/acl/permission/toAssign/',
  // 权限分配保存接口
  ROLE_PERMISSION_SAVE_URL = '/admin/acl/permission/doAssign/'
}

// 获取列表数据方法
export const reqRoleList = (page: any, limit: any, roleName: any) => {
  return request.get<any, any>(
    API.ROLE_LIST_URL + `${page}/${limit}/?roleName=${roleName}`
  )
}

// 删除方法
export const delRoleReq = (id: any) => {
  return request.delete<any, any>(API.ROLE_DELETE_URL + id)
}

// 保存
export const addOrUpdateRoleReq = (data: any) => {
  if (data.id) {
    return request.put<any, any>(API.ROLE_UPDATE_URL, data)
  } else {
    return request.post<any, any>(API.ROLE_ADD_URL, data)
  }
}

// 根据角色获取菜单方法
export const getRolePermissionReq = (roleId: any) => {
  return request.get<any, any>(API.ROLE_PERMISSION_LIST_URL + roleId)
}

export const saveRolePermissionReq = (roleId: any, permissionId: any) => {
  return request.post<any, any>(
    API.ROLE_PERMISSION_SAVE_URL +
      `?roleId=${roleId}&permissionId=${permissionId}`
  )
}
